﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;

namespace C12_Ex03_Shaked_032675316_Itay_032511057
{
    public class ImageGrayScaleDecorator : ImageFormaterDecorator
    {
        public ImageGrayScaleDecorator(ImageFormaterDecorator i_ImageStringFormatter) : base(i_ImageStringFormatter)
        {
        }

        public ImageGrayScaleDecorator() : base()
        {
        }

        public override Image FormatImage(Image i_Image)
        {
            i_Image = base.FormatImage(i_Image);
            Bitmap bitMap = new Bitmap(i_Image);
            int rgb;
            Color color;

            for (int y = 0; y < bitMap.Height; y++)
            {
                for (int x = 0; x < bitMap.Width; x++)
                {
                    color = bitMap.GetPixel(x, y);
                    rgb = (int)((color.R + color.G + color.B) / 3);
                    bitMap.SetPixel(x, y, Color.FromArgb(rgb, rgb, rgb));
                }
            }

            return (Image)bitMap;
        }
    }
}
